<#include "/common/h-ui-base-css.html">
<#include "/common/h-ui-base-js.html">
<#include "/common/validation-js.html">
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2" style="text-align: center"><span class="c-red">*</span>登录名称：</label>
			<div class="formControls col-xs-8 col-sm-10">
				<input type="text" class="input-text" value="${user.username!}" placeholder="" id="username" name="username" <#if flag=='edit'>readonly style="background-color:#cef0ce;border:0;"</#if>>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2" style="text-align: center" ><span class="c-red">*</span>显示名称：</label>
			<div class="formControls col-xs-8 col-sm-10">
				<input type="text" class="input-text" autocomplete="off" value="${user.nickname!}" placeholder="" id="nickname" name="nickname">
			</div>
		</div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2" style="text-align: center" ><span class="c-red">*</span>密码：</label>
            <div class="formControls col-xs-8 col-sm-10">
                <input type="password" class="input-text" autocomplete="off" value="" placeholder="" id="password" name="password">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2" style="text-align: center" ><span class="c-red">*</span>确认密码：</label>
            <div class="formControls col-xs-8 col-sm-10">
                <input type="password" class="input-text" autocomplete="off" value="" placeholder="" id="password2" name="password2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"  style="text-align: center"><span class="c-red">*</span>公司：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:360px;">
		<select class="select" name="group_id" id="group_id" size="1">
			<option value="-1">---请选择组别---</option>
			<#if group_list??>
				<#list group_list as g>
			        <option value="${g.key}" <#if user.belongTo??><#if g.key==user.belongTo>selected</#if></#if>>${g.value}</option>
				</#list>
			</#if>
		</select>
		</span> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"  style="text-align: center"><span class="c-red">*</span>数据权限：</label>
            <div class="formControls col-xs-8 col-sm-9">
			<span class="select-box" style="width:360px;">
				<select class="select" name="power_level" id="power_level" size="1">
					<option value="-1">---请选择职务---</option>
					<#if level_list??>
						<#list level_list as g>
			        		<option value="${g.key}" <#if user.powerLevel??><#if g.key==user.powerLevel>selected</#if></#if>>${g.value}</option>
						</#list>
					</#if>
				</select>
			</span>
            </div>
        </div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3" style="text-align: center"><span class="c-red">*</span>角色：</label>
            <div class="formControls col-xs-8 col-sm-10 skin-minimal">
				<#list role_list as role>
                    <div class="check-box">
                        <input type="checkbox" <#if role_id_list??><#if role_id_list?seq_contains(role.key)>checked="checked"</#if></#if>  id="${role.roleKey}" name="${role.roleKey}">
                        <label for="checkbox-5">${role.value}</label>
                    </div>
				</#list>
            </div>
		</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
	</form>
</article>
<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript">

	$(function(){
	var id = ${user.id!-1};
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	$("#form-admin-add").validate({
		rules:{
            username:{
				required:true,
                isCheck:true,
				minlength:3,
				maxlength:16
			},
            nickname:{
				required:true,
                minlength:2,
                maxlength:16
			},
			password:{
                required:true,
                minlength:4,
                maxlength:16
			},
            password2:{
                equalTo: "#password"
			},
            role_id:{
				required:true,
                isSelect:true
			},
            group_id:{
				required:true,
                isSelect:true
			},
            power_level:{
				required:true,
                isSelect:true
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "/user-ins-upd-del/"+id ,
				data :$("form-admin-add").serialize(),
				async:false,
				success: function(data){
					layer.msg('添加成功!',{icon:1,time:1000});
				},
                error: function(XmlHttpRequest, textStatus, errorThrown){
					layer.msg('error!',{icon:1,time:1000});
				}
			});
			var index = parent.layer.getFrameIndex(window.name);
            var handler = '/user-list-json/0/20';
            parent.$('#admin_table').datagrid('options').url = handler;
            parent.$('#admin_table').datagrid('reload');
			parent.layer.close(index);
		}
	});
    jQuery.validator.addMethod("isSelect", function(value, element) {
        return this.optional(element) || ( value!="-1" );
    }, "请选择");
    jQuery.validator.addMethod("isCheck", function(value, element) {
        var id = ${user.id!-1};
        var flag = '';
        $.ajax({
			type :'post',
			url : '/user-check/'+value+'/'+id,
			async :false,
			success :function(data){
                flag = data;
			}
		});
        return this.optional(element) || ( flag!="error" );
    }, "登录名称重复，请重新输入");
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
